#pragma once
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
#include <sstream>
#include "Student.h"


using namespace std;

class StudentRegister
{
private:
	vector<Student> v;


public:
	

	StudentRegister(void)
	{
			
	}

	void Add(Student s)
	{
		v.push_back(s);
	}

	string List()
	{
		ostringstream oss;
		string s = "";

		for(int i = 0; i < v.size(); i++)
		{
			cout << v[i] << endl;
		}

		return oss.str();
	}
	
	void WriteToFile()
	{

		ofstream fout;
		fout.open("test.txt");

		for (int i = 0; i < v.size(); i++)
		{	
			fout << v[i] << endl;
		}

		fout.close();
	}

	void ReadFromFile()
	{
		ifstream fin;
		fin.open("test.txt");

		if ( !fin.good() )
		{
			cout << "Filen gick inte att oppna" << endl;
		}

		while ( !fin.eof() )
		{
			string str;
			getline(fin, str);
			cout << str << endl;
			istringstream iss(str);
			Student s;
			iss >> s;
			if(s.GetEnrollmentYear() != -1)
			v.push_back(s);
		}

		fin.close();
	}

	/*void AddStudent()
	{
		
		Student s;
		cout << ("(Fornamn,Efternamn,Inskrivningsar)=");
		cin >> s;
		v.push_back(s);

	}

	void DeleteStudent()
	{
		
		string s = "";
		string c = "";
		int ar = -1;
		cout << "Ta bort student" << endl;
		cout << "Skriv fornamn: ";
		cin >> s;
		cout << "Skriv Efternamn: ";
		cin >> c;
		cout << "Skriv inskrivningsar: ";
		cin >> ar;

		for (int i = 0; i < v.size(); i++)
		{
			if ((v[i].GetFirstName() == s) && (v[i].GetSecondName() == c) && (v[i].GetEnrollmentYear() == ar))
			{
				v.erase (v.begin() + i);
				return;
			}
		}
	}*/



	

	

	

	

	~StudentRegister(void)
	{
	}
};

